#include <stdio.h>
#include <string.h>

unsigned int my_strlen(char *s1)
{
    int length = 0;
    while (*(s1 + length) != '\0')
    {
        length += 1;
    }
    return length;
}

char *my_strcpy(char *dest, char *src)
{
#if 0 
    int index = 0;
    while (src[index] != '\0')
    {
        dest[index] = src[index];
        index++;
    }
    dest[index]='\0';
#endif
    while (*src != '\0')
    {
        *dest++ = *src++;
    }
    *dest = '\0';
    return dest;
}

int my_strcmp(char *dest, char *src)
{
#if 0
    while (*dest != '\0' && *src != '\0')
    {
        if (*dest - *src != 0)
        {
            return *dest - *src;
        }
        dest++;
        src++;
    }
    return *dest - *src;
#endif
    while (*dest != '\0')
    {
        if (*dest != *src)
        {
            return *dest - *src; // 两个字符ascii进行减法运算
        }
        ++dest;
        ++src;
    }
    return *dest - *src;
}

#if 0 
char *my_strcat(char *dest, char *src)
{

}
#endif

int main(int argc, char const *argv[])
{
#if 0
    unsigned int len = my_strlen("welcome to beijing");
    size_t strl = strlen("welcome to beijing");
    printf("%u %ld\n", len, strl);
#endif

#if 0
    char *str1 = "welcome to beijing";
    char str2[100];
    char str3[100];
    my_strcpy(str2, str1);
    strcpy(str3, str1);

    printf("retstr2=%s retstr3=%s\n", str2, str3);
#endif
#if 0
    char *str1 = "welcome to beijing";
    char *str2 = "welcome to shanghai";
    int cmp1 = my_strcmp(str1, str2);
    int cmp2 = strcmp(str1, str2);
    printf("my_strcmp=%d ,strcmp=%d", cmp1, cmp2);
#endif
    
    /* code */
    return 0;
}
